package com.spirng.leetcode.day03;

import java.util.HashSet;

public class IsHappy {
    public static void main(String[] args) {
        isHappy(19);
    }
    public static boolean isHappy(int n) {
        HashSet<Integer> hashSet = new HashSet<>();
        while (n!=1){
            String s = String.valueOf(n);
            int sum=0;
            for (int i = 0; i < s.length(); i++) {
                sum+=(s.charAt(i)-'0')*(s.charAt(i)-'0');
            }
            n=sum;
            if(hashSet.contains(n)){
                return false;
            }

            hashSet.add(n);
        }
        return true;
    }
}
